﻿$.ajaxSetup({
    cache: true
});
//var ip = "http://218.95.181.55:922";
var ip = "http://192.168.31.177:2000";
//var ip = "http://222.77.181.149:1300";
var api = "/api/DataApi";
jQuery.support.cors = true;
(function () {
    window.console = {};
    var func = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'trace', 'group', 'groupEnd', 'time', 'timeEnd', 'profile', 'profileEnd', 'count', 'exception', 'table'];
    for (var i = 0, j = func.length; i < j; i++) {
        window.console[func[i]] = function () { }
    }
})();
//命名空间
jQuery.namespace = function () {
    var a = arguments, o = null, i, j, d;
    for (i = 0; i < a.length; i = i + 1) {
        d = a[i].split(".");
        o = jQuery;
        for (j = (d[0] == "jQuery") ? 1 : 0; j < d.length; j = j + 1) {
            o[d[j]] = o[d[j]] || {};
            o = o[d[j]];
        }
    }
    return o;
};
String.prototype.Trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function () {
    return this.replace(/(^\s*)/g, "");
}
String.prototype.RTrim = function () {
    return this.replace(/(\s*$)/g, "");
}
Date.prototype.format = function (format) {
    format = jQuery.usi.core.isNullOrEmpty(format) ? "yyyy-MM-dd hh:mm:ss" : format
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),    //day
        "h+": this.getHours(),   //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(format))
        format = format.replace(RegExp.$1,
            RegExp.$1.length == 1 ? o[k] :
                ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}
//扩展方法
$.extend({
    parseJSON: function (str) {
        return eval('(' + str + ')')
    },
    toJSON: function (object) {
        var type = typeof object;
        if ('object' == type) {
            if (Array == object.constructor) type = 'array';
            else if (RegExp == object.constructor) type = 'regexp';
            else type = 'object';
        }
        switch (type) {
            case 'undefined':
            case 'unknown':
                return;
                break;
            case 'function':
            case 'boolean':
            case 'regexp':
                return object.toString();
                break;
            case 'number':
                return isFinite(object) ? object.toString() : 'null';
                break;
            case 'string':
                return '"' + object.replace(/(\\|\")/g, "\\$1") + '"';
                break;
            case 'object':
                if (object === null) return 'null';
                var results = [];
                for (var property in object) {
                    var value = $.toJSON(object[property]);
                    if (value !== undefined) results.push($.toJSON(property) + ':' + value);
                }
                return '{' + results.join(',') + '}';
                break;
            case 'array':
                var results = [];
                for (var i = 0; i < object.length; i++) {
                    var value = $.toJSON(object[i]);
                    if (value !== undefined) results.push(value);
                }
                return '[' + results.join(',') + ']';
                break;
        }
    }
});
//表单提交转换json
$.fn.form2json = function () {
    var obj = {};
    $(this).find('input[name],select[name],textarea[name]').each(function (index, item) {
        var item = $(item);
        var name = item.attr("name");
        if ((item.prop("type") != "file") && !jQuery.usi.core.isNullOrEmpty(name)) {
            if (item.prop("type") == 'radio' && item.prop("checked") == false) {
                return;
            }
            var value = item.val();
            value = value == null ? "" : value.Trim();
            if (item[0].type == "textarea") {
                value = value.replace(/\n/g, "<br />");
            }
            var tmpArray = name.split('.');
            var array = [];
            for (i = 0; i < tmpArray.length; i++) {
                array.push(tmpArray[i]);
                var evalString = "obj." + array.join('.');
                if (jQuery.usi.core.isNullOrEmpty(eval(evalString))) {
                    eval(evalString + "={};");
                }
            }
            value = value.replace(/'/g, "‘");
            value = value.replace(/\%/g, "%25");
            value = value.replace(/\+/g, "%2B");
            //value = value.replace(/\//g, "%2F");
            //value = value.replace(/\ /g, "%20");
            //value = value.replace(/\?/g, "%3F");
            value = value.replace(/\#/g, "%23");
            //value = value.replace(/\&/g, "%23");
            // value = value.replace(/\=/g, "%3D");
            value = value.replace(/\０/g, "0");
            value = value.replace(/\１/g, "1");
            value = value.replace(/\２/g, "2");
            value = value.replace(/\３/g, "3");
            value = value.replace(/\４/g, "4");
            value = value.replace(/\５/g, "5");
            value = value.replace(/\６/g, "6");
            value = value.replace(/\７/g, "7");
            value = value.replace(/\８/g, "8");
            value = value.replace(/\９/g, "9");
            eval("obj." + array.join('.') + "='" + jQuery.usi.core.string2Json(value) + "';");
        }
    });
    return $.toJSON(obj);
}
$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
}
//表单填充数据
$.fn.json2form = function (o) {
    if (o == null) {
        var form = document.forms[$(this).attr('name')];
        if (form !== undefined) {
            form.reset();
            return true;
        } else {
            return false;
        }
    }
    var $this = this;
    var a = $this.serializeArray();
    $.each(a, function (i, n) {
        var $t = $('input[name=\'' + this.name + '\'],textarea[name=\'' + this.name + '\'],select[name=\'' + this.name + '\']', $this);
        var objJson = null;
        var objForm = {};
        try {
            objJson = eval("o." + this.name + "");
            objForm = {
                isload: jQuery.usi.core.isNullOrEmpty($t.attr("isload")) ? "true" : $t.attr("isload"),
                name: this.name,
                datasourceurl: $t.attr("datasourceurl"), //数据源(地址)
                datasourcekey: $t.attr("datasourcekey"), //数据源(数据字典)
                renderfun: $t.attr("renderfun"), //渲染调用某个方法
                datasource: null
            }
        } catch (e) {
            return true;
        }
        if (objForm.isload == "true") {
            if (!jQuery.usi.core.isNullOrEmpty(objForm.datasourceurl)) {
                jQuery.usi.core.postCache(objForm.datasourceurl, null, true, function (resultDataSource) {
                    objForm.datasource = resultDataSource.data;
                });
            }
            if (!jQuery.usi.core.isNullOrEmpty(objForm.datasourcekey)) {
                try {
                    objForm.datasource = eval("Data_" + objForm.datasourcekey);
                } catch (e) {
                    objForm.datasource = [];
                }
            }
            //判断是否是时间类型 如果是将进行转换
            objJson = objJson != null ? objJson : "";
            //判断是否是时间类型 如果是将进行转换
            if (jQuery.usi.core.isDate(objJson)) {
                objJson = jQuery.usi.core.formatDate(objJson);
            }
            objJson = jQuery.usi.core.getDataSourceName(objJson, objForm.datasource);
            if (!jQuery.usi.core.isNullOrEmpty(objForm.renderfun)) {
                if (jQuery.usi.core.isMethod(eval(objForm.renderfun))) {
                    var customMethod = eval((objForm.renderfun));
                    objJson = customMethod(o);
                }
            }
            if ($t[0].type == "textarea" && objJson.replace != null) {
                objJson = objJson.replace(/<br \/>/g, "\n");
            }
            if ($t.attr("type") == 'radio') {
                $.each($t, function (i, n) {
                    $(this).removeAttr("checked");
                    if ($(this).val() == objJson) {
                        $(this).prop("checked", true);
                    } else {
                        $(this).prop("checked", false);
                    }
                });
            } else {
                if (!jQuery.usi.core.isNullOrEmpty(objJson)) {
                    $t.val(objJson.valueOf());
                    //验证重写
                    if ($t.attr("isvalidate")) {
                        $t.trigger("validate");
                    }
                } else {
                    $t.val("");
                }
            }
        } else {
            $t.val("");
        }
    });
    $("span[name],div[name]", $this).each(function (index, item) {
        var objJson = null;
        item = $(item);
        var spanObj = {
            isload: jQuery.usi.core.isNullOrEmpty(item.attr("isload")) ? "true" : item.attr("isload"),
            name: item.attr("name"),
            datasourceurl: item.attr("datasourceurl"), //数据源(地址)
            datasourcekey: item.attr("datasourcekey"), //数据源(数据字典)
            renderfun: item.attr("renderfun"), //渲染调用某个方法
            datasource: null
        }
        if (spanObj.isload == "true") {
            if (!jQuery.usi.core.isNullOrEmpty(spanObj.datasourceurl)) {
                jQuery.usi.core.postCache(spanObj.datasourceurl, null, true, function (resultDataSource) {
                    spanObj.datasource = resultDataSource.data;
                });
            }
            if (!jQuery.usi.core.isNullOrEmpty(spanObj.datasourcekey)) {
                try {
                    spanObj.datasource = eval("Data_" + spanObj.datasourcekey);
                } catch (e) {
                    spanObj.datasource = [];
                }
            }
            try {
                objJson = eval("o." + spanObj.name + "");
                //判断是否是时间类型 如果是将进行转换
                objJson = objJson != null ? objJson : "";
                if (jQuery.usi.core.isDate(objJson)) {
                    objJson = jQuery.usi.core.formatDate(objJson);
                }
                objJson = jQuery.usi.core.getDataSourceName(objJson, spanObj.datasource);
                if (!jQuery.usi.core.isNullOrEmpty(spanObj.renderfun)) {
                    if (jQuery.usi.core.isMethod(eval(spanObj.renderfun))) {
                        var customMethod = eval((spanObj.renderfun));
                        objJson = customMethod(o);
                    }
                }
                if (item.prop("fieldtype") == "textarea") {
                    objJson = objJson.replace(/\n/g, "<br />");
                }
                item.html(objJson.valueOf());
            } catch (e) {
            }
        }
    });
};
//核心
jQuery.namespace('jQuery.usi.core');
jQuery.namespace('jQuery.usi.tools');
//督查检查
jQuery.namespace('jQuery.PeriodSupervision');
//特种设备
jQuery.namespace('jQuery.SpecialEquipment.UnitArchive');
jQuery.namespace('jQuery.SpecialEquipment.EquipmentArchive');
jQuery.namespace('jQuery.SpecialEquipment.WorkType');
jQuery.namespace('jQuery.SpecialEquipment.WorkItem');
jQuery.namespace('jQuery.SpecialEquipment.WorkLevel');
jQuery.namespace('jQuery.SpecialEquipment.EquipmentVarietyLibrary');
jQuery.namespace('jQuery.SpecialEquipment.JobPersonArchive');
jQuery.namespace('jQuery.SpecialEquipment.HdEquipmentArchive');
jQuery.namespace('jQuery.SpecialEquipment.ContractArchive');
jQuery.namespace('jQuery.SpecialEquipment.MaintainRecord');
jQuery.namespace('jQuery.SpecialEquipment.Document');
jQuery.namespace('jQuery.SpecialEquipment.Check');
jQuery.namespace('jQuery.SpecialEquipment.SpecialCheck');
jQuery.namespace('jQuery.SpecialEquipment.SpecialEquipmentCheckContent');
jQuery.namespace('jQuery.SpecialEquipment.SpecialEquipmentCheckItem');

//日常检查
jQuery.namespace('jQuery.DailySupervision.Normal0');
jQuery.namespace('jQuery.DailySupervision.Normal2');
jQuery.namespace('jQuery.DailySupervision.Normal4');
jQuery.namespace('jQuery.DailySupervision.Normal6');
jQuery.namespace('jQuery.DailySupervision.Normal8');
jQuery.namespace('jQuery.DailySupervision.Normal10');
jQuery.namespace('jQuery.DailySupervision.Normal12');
jQuery.namespace('jQuery.DailySupervision.Normal14');
jQuery.namespace('jQuery.DailySupervision.Normal16');
jQuery.namespace('jQuery.DailySupervision.Normal18');
jQuery.namespace('jQuery.DailySupervision.Normal20');
jQuery.namespace('jQuery.DailySupervision.Normal22');
jQuery.namespace('jQuery.DailySupervision.Normal24');
jQuery.namespace('jQuery.DailySupervision.Normal26');

//三级核查配置项
jQuery.namespace('jQuery.CheckBigCategoriesConfig');
jQuery.namespace('jQuery.CheckSmallCategoriesConfig');
jQuery.namespace('jQuery.CheckProjectConfig');

//食品生产风险等级三级配置项
jQuery.namespace('jQuery.FoodProductionBigType');
jQuery.namespace('jQuery.FoodProductionSmallType');
jQuery.namespace('jQuery.FoodProductionDetails');

//绩效管理
jQuery.namespace('jQuery.PerformanceManagement.Config_Year');
jQuery.namespace('jQuery.PerformanceManagement.Config_Type');
jQuery.namespace('jQuery.PerformanceManagement.Config_DataTaskType');
jQuery.namespace('jQuery.PerformanceManagement.TargetManage1');
jQuery.namespace('jQuery.PerformanceManagement.TargetManage2');
jQuery.namespace('jQuery.PerformanceManagement.TargetManage3');
jQuery.namespace('jQuery.PerformanceManagement.TargetManage4');
jQuery.namespace('jQuery.PerformanceManagement.TargetManage5');

//考核管理
jQuery.namespace('jQuery.PerformanceManagement.Performance');
jQuery.namespace('jQuery.PerformanceManagement.Performance1');
jQuery.namespace('jQuery.PerformanceManagement.Assessment1');
//26个字母
var English = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
//核心库
jQuery.usi.core = {
    fileCachePath: "/File/Cache/",
    dataGridHeadCache: [], //{Guid:"",Data:null} dataGrid头部数据缓存
    dataCache: [], //数据缓存 {Url:"",Data:null}
    loginUser: [],  //登录人员信息
    //字符窜转json
    string2Json: function (s) {
        var newstr = "";
        for (var i = 0; i < s.length; i++) {
            c = s.charAt(i);
            switch (c) {
                case '\"':
                    newstr += "\\\"";
                    break;
                case '\\':
                    newstr += "\\\\";
                    break;
                case '/':
                    newstr += "\\/";
                    break;
                case '\b':
                    newstr += "\\b";
                    break;
                case '\f':
                    newstr += "\\f";
                    break;
                case '\n':
                    newstr += "\\n";
                    break;
                case '\r':
                    newstr += "\\r";
                    break;
                case '\t':
                    newstr += "\\t";
                    break;
                default:
                    newstr += c;
            }
        }
        return newstr;
    },
    //根据数据源与标识获取显示值数据源的数据必须是id与name组成的数据
    getDataSourceName: function (value, data) {
        if (data != null) {
            $.each(data, function (index, item) {
                if (item.id == value) {
                    value = item.name;
                    return false;
                }
            });
        }
        return value;
    },
    //判断是否是方法
    isMethod: function (fun) {
        if (fun != null && typeof (fun) == "function") {
            return true;
        } else {
            return false;
        }
    },
    //空方法
    emptyMethod: function () {
    },
    //判断是否为空
    isNullOrEmpty: function (str) {
        if (str == null) {
            return true;
        }
        else if (str == "null") {
            return true;
        } else if (str.toString() == "0") {
            return false;
        } else if (str == "" || str.toString().Trim() == "") {
            return true;
        }
        return false;
    },
    //生成GUID
    newGuid: function () {
        var guid = "";
        jQuery.usi.core.post("/Base/GetGuid", null, true, function (data) {
            guid = data.data;
        });
        return guid;
    },
    isDate: function (jsondate) {
        var isDate = false;
        if (!jQuery.usi.core.isNullOrEmpty(jsondate)) {
            var date;
            if (jsondate.toString().indexOf("/Date(") == 0) {
                isDate = true;
            } else {
                try {
                    //date = new Date(jsondate);
                    isDate = false;
                } catch (e) {
                    isDate = false;
                }
            }
        }
        return isDate;
    },
    formatDate: function (jsondate, format) {
        if (jsondate != null && jsondate != "") {
            if (jQuery.usi.core.isNullOrEmpty(format)) {
                format = "yyyy-M-d hh:mm:ss";
            }
            var date;
            if (!jQuery.usi.core.isNullOrEmpty(jsondate) && jsondate.toString().indexOf("/Date(") == 0) {
                date = new Date(parseInt(jsondate.replace("/Date(", "").replace(")/", ""), 10));
            } else {
                date = new Date(jsondate);
            }
            var value = date.format(format);
            value = value.replace(" 00:00:00", "");
            if (value == "1-1-1 08:00:00") {
                value = "";
            }
            return value;
        } else {
            return "";
        }
    },
    //打开弹窗
    layer_show: function (config) {
        var newconfig = {
            type: jQuery.usi.core.isNullOrEmpty(config.type) ? 2 : config.type,
            fix: jQuery.usi.core.isNullOrEmpty(config.fix) ? false : config.fix,
            title: jQuery.usi.core.isNullOrEmpty(config.title) ? "" : config.title,
            content: jQuery.usi.core.isNullOrEmpty(config.content) ? "404.html" : config.content,
            area: [jQuery.usi.core.isNullOrEmpty(config.width) ? "auto" : config.width, jQuery.usi.core.isNullOrEmpty(config.height) ? "auto" : config.height],
            shade: jQuery.usi.core.isNullOrEmpty(config.shade) ? "0.4" : config.shade,
            maxmin: jQuery.usi.core.isNullOrEmpty(config.maxmin) ? true : config.maxmin,
            zIndex: jQuery.usi.core.isNullOrEmpty(config.zIndex) ? 19811020 : config.zIndex,
            moveOut: jQuery.usi.core.isNullOrEmpty(config.moveOut) ? false : config.moveOut,

            offset: "10px",
            success: !jQuery.usi.core.isMethod(config.success) ? jQuery.usi.core.emptyMethod : (function (layerobj) {
                jQuery.usi.tools.form.renderValidate(layerobj);
                layer.style(layer.index, {
                    width: $(layerobj).css("width"),
                    height: $(layerobj).css("height")
                });
                config.success(layerobj)
            }), //成功回调
            close: !jQuery.usi.core.isMethod(config.close) ? jQuery.usi.core.emptyMethod : config.close, //关闭回调
            min: function (layerobj) {
            },
            full: function (layerobj) {
                $(layerobj).attr("heightData", $(layerobj).find(".layui-layer-content").css('height'));
                //var contentHeight = $(layerobj).height()-42+"px";
                //alert(contentHeight);
                $(layerobj).find(".layui-layer-content").css('height', $(layerobj).parent().height() - 62 + 'px');
            },
            restore: function (layerobj) {
                $(layerobj).find(".layui-layer-content").css('height', $(layerobj).attr("heightData"));
            },
            loading: { type: jQuery.usi.core.isNullOrEmpty(config.loadingType) ? 0 : config.loadingType }
        };
        if (newconfig.type == "1") {
            jQuery.usi.core.getHtml(newconfig.content, {}, true, function (content) {
                newconfig.content = content;
            });
        }
        layer.open(newconfig);
    },
    //关闭弹窗
    layer_close: function (config) {
        if (jQuery.usi.core.isNullOrEmpty(config.index)) {
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            if (jQuery.usi.core.isNullOrEmpty(index)) {
                var index = layer.index;
                if (!jQuery.usi.core.isNullOrEmpty(index)) {
                    layer.close(index);
                } else {
                    layer.closeAll();
                }
            } else {
                parent.layer.close(index);
            }
        } else {
            layer.close(config.index);
        }

    },
    getHtml: function (url, param, async, callback, errorCallback) {
        if (!jQuery.usi.core.isNullOrEmpty(async) && async) {
            $.ajaxSetup({
                async: false
            });
        }
        jQuery.usi.tools.loading.show();
        $.get(url, param, function (resultData) {
            jQuery.usi.tools.loading.hide();
            if (callback != null && typeof (callback) == "function") {
                callback(resultData);
            }
        });
        if (!jQuery.usi.core.isNullOrEmpty(async) && async) {
            $.ajaxSetup({
                async: true
            });
        }
    },
    //地址,请求参数,是否同步，回调
    postHtml: function (url, param, async, callback, errorCallback) {
        if (!jQuery.usi.core.isNullOrEmpty(async) && async) {
            $.ajaxSetup({
                async: false
            });
        }
        jQuery.usi.tools.loading.show();
        $.post(url, param, function (resultData) {
            jQuery.usi.tools.loading.hide();
            if (callback != null && typeof (callback) == "function") {
                callback(resultData);
            }
        });
        if (!jQuery.usi.core.isNullOrEmpty(async) && async) {
            $.ajaxSetup({
                async: true
            });
        }
    },
    //地址,请求参数,是否同步，回调
    getJson: function (url, param, async, callback, errorCallback) {
        if (!jQuery.usi.core.isNullOrEmpty(async) && async) {
            $.ajaxSetup({
                async: false
            });
        }
        jQuery.usi.tools.loading.show();
        $.getJSON(url, param, function (resultData) {
            jQuery.usi.tools.loading.hide();
            if (callback != null && typeof (callback) == "function") {
                callback(resultData);
            }
        });
        if (!jQuery.usi.core.isNullOrEmpty(async) && async) {
            $.ajaxSetup({
                async: true
            });
        }
    },
    //地址,请求参数,是否同步,回调,失败回调
    get: function (url, param, async, callback, errorCallback) {
        jQuery.usi.tools.loading.show();
        $.ajax({
            url: url,
            type: "get",
            data: param,
            dataType: "json",
            async: jQuery.usi.core.isNullOrEmpty(async) ? true : !async,
            success: function (resultData) {
                jQuery.usi.tools.loading.hide();
                if (resultData.accreditStatus != "0") {
                    layer.alert(jQuery.usi.core.getAccreditMsg(resultData.accreditStatus));
                    jQuery.usi.core.backHome();
                } else {
                    if (!resultData.isExpired) {
                        jQuery.usi.core.backHome();
                    } else {
                        //if (!jquery.usi.core.isnullorempty(resultdata.msg)) {
                        //    layer.alert(resultdata.msg);
                        //}
                        //成功的时候才执行回调
                        if (resultData.success) {
                            if (jQuery.usi.core.isMethod(callback)) {
                                callback(resultData);
                            }
                        }
                        else {
                            if (jQuery.usi.core.isMethod(errorCallback)) {
                                errorCallback(resultData);
                            }
                        }
                    }
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                jQuery.usi.tools.loading.hide();
            },
            complete: function (XMLHttpRequest, textStatus) {
                this; // 调用本次AJAX请求时传递的options参数
            }
        });
    },
    //地址,请求参数,是否同步,回调,失败回调
    post: function (url, param, async, callback, errorCallback) {
        jQuery.usi.tools.loading.show();
        $.ajax({
            url: url,
            type: "post",
            data: param,
            dataType: "json",
            async: jQuery.usi.core.isNullOrEmpty(async) ? true : !async,
            success: function (resultData) {
                jQuery.usi.tools.loading.hide();
                if (resultData.accreditStatus != "0") {
                    layer.alert(jQuery.usi.core.getAccreditMsg(resultData.accreditStatus));
                    jQuery.usi.core.backHome();
                } else {
                    if (!resultData.isExpired) {
                        jQuery.usi.core.backHome();
                    } else {
                        if (!jQuery.usi.core.isNullOrEmpty(resultData.msg)) {
                            layer.alert(resultData.msg);
                        }
                        //成功的时候才执行回调
                        if (resultData.success) {
                            if (jQuery.usi.core.isMethod(callback)) {
                                callback(resultData);
                            }
                        }
                        else {
                            if (jQuery.usi.core.isMethod(errorCallback)) {
                                errorCallback(resultData);
                            }
                        }
                    }
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                jQuery.usi.tools.loading.hide();
            },
            complete: function (XMLHttpRequest, textStatus) {
                this; // 调用本次AJAX请求时传递的options参数
            }
        });
    },
    //地址,请求参数,是否同步,回调,失败回调
    postCache: function (url, param, async, callback, errorCallback) {
        jQuery.usi.tools.loading.show();
        var exist = false;
        $.each(jQuery.usi.core.dataCache, function (index, item) {
            if (item.Url == url) {
                if (jQuery.usi.core.isMethod(callback)) {
                    callback(item.Data);
                }
                exist = true;
                return false;
            }
        });
        if (!exist) {
            jQuery.usi.core.post(url, param, async, function (resultData) {
                jQuery.usi.core.dataCache.push({ Url: url, Data: resultData }); //放入缓存
                if (jQuery.usi.core.isMethod(callback)) {
                    callback(resultData);
                }
            });
        }
        jQuery.usi.tools.loading.hide();
    },
    //地址,请求参数,是否同步,回调,失败回调
    deletePost: function (url, param, callback) {
        layer.confirm("删除需谨慎,删除后的数据将无法恢复,是否要立即删除！", function () { jQuery.usi.core.post(url, param, false, callback); });
    },
    //回到首页
    backHome: function () {
        if (window.parent == window) {
            window.location = "/login.html";
        } else {
            window.parent.location = "/login.html";
        }
    },
    //获取URL参数
    getURLParam: function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return "";
    },
    //获取字符实际长度
    getStrLength: function (str) {
        if (!jQuery.usi.core.isNullOrEmpty(str)) {
            var cArr = str.match(/[^\x00-\xff]/ig);
            return str.length + (cArr == null ? 0 : cArr.length);
        } else {
            return str;
        }
    },
    //设置字符长度
    setString: function (str, len) {
        var strlen = 0;
        var s = "";
        for (var i = 0; i < str.length; i++) {
            if (str.charCodeAt(i) > 128) {
                strlen += 2;
            } else {
                strlen++;
            }
            s += str.charAt(i);
            if (strlen >= len) {
                return s;
            }
        }
        return s;
    },
    getJqueryById: function (id) {
        return $(document.getElementById(id));
    },
    isArray: function (arr) {
        return Object.prototype.toString.apply(arr) === "[object Array]";
    },
    //根据字符串转换为方法
    parseEvent: function (fun) {
        try {
            return eval(fun);
        } catch (e) {
            jQuery.usi.core.emptyMethod();
        }
    },
    getAccreditMsg: function (code) {
        var msg = "错误编号:" + code;
        switch (code) {
            case 10000:
                return "找不到指定的授权文件";
            case 10001:
                return "授权文件被破坏";
            case 10002:
                return "授权号错误";
            case 10003:
                return "授权已过期";
            case 11000:
                return "授权出现问题" + msg;
            default:
                return "";
        }
    }
}
function GetLoginUserUnid() {
    var u = parent.jQuery.usi.core.loginUser.user;
    if (u != null) {
        return u.unid;
    } else {
        return null;
    }
}
//比较
function contrastDate(d1, d2) {
    //时间比较
    var arrayD1 = d1.split("-");
    var date1 = new Date(arrayD1[0], arrayD1[1], arrayD1[2]);
    var arrayD2 = d2.split("-");
    var date2 = new Date(arrayD2[0], arrayD2[1], arrayD2[2]);
    return date1 > date2;
}
